package com.wowangz.cms.syscore.api;


import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Controller
public class BaseController 
{
	protected UserContext userContext = null;
	
	
	public UserContext getUserContext() {
		return userContext;
	}


	public void setUserContext(UserContext userContext) {
		this.userContext = userContext;
	}

	public HttpServletRequest getRequest()
	{
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		return request;
	}
	
	 /**
	  * 数据绑定 日期类型数据传输转换
	  * @param binder
	  */
	 @InitBinder  
	 protected void ininBinder(WebDataBinder binder)
	 {  
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf,true));  
	 }  


	
}
